<?php

namespace admin\controller;

class Controller{
    //缓存数据
    private $data = [];
    //设置缓存数据
    public function setData($key, $value = null){
        if(is_array($key)){
            $this->data = array_merge($this->data,$key);
        } else {
            $this->data[$key] = $value;
        }
    }
    //显示（渲染）视图
    public function view ($viewName){
        $viewPath = $_SERVER['DOCUMENT_ROOT'].'/blog_system/admin/view/'.$viewName.'.php';
        if(file_exists($viewPath) && is_file($viewPath)){
            extract($this->data);   
            ob_start();
            include $viewPath;
            $content = ob_get_contents();
            ob_end_clean();
            return $content;
        } else {
            echo 'view : ' .$viewPath.' is not exists';
            exit();
        }
    }
}